<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>产品配置</el-breadcrumb-item>
        <el-breadcrumb-item>功能开关</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
       
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
      >
        <!-- 自定义操作栏 -->
        <template slot-scope="scope" slot="menu">
          <el-button
            v-if="scope.row.status == 0"
            icon="el-icon-open"
            type="text"
            size="small"
            @click.stop="openAndClose(scope.row, 1)"
            >隐藏
          </el-button>
          <el-button
            v-if="scope.row.status == 1"
            icon="el-icon-open"
            type="text"
            size="small"
            @click.stop="openAndClose(scope.row, 0)"
            >展示
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import {
  appSwitchMember as baseURL
} from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      radio: "1",
      page: {
        // total: 0,
        // pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      oldForm: {},
      // default: {
      //   orderByList: "create_time&ASC",
      // },
      option: {
        border: true,
        index: false,
        label: "序号",
        tip: true,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        align: "center",
        headerAlign: "center",
        column: [
          {
            label: "名称",
            prop: "title",
            type: "input",
            search:false
          },
          {
            label: "状态",
            prop: "status",
            type: "select",
            search: false,
            dicData: [
              {
                label: "展示",
                value: 0,
              },
              {
                label: "隐藏",
                value: 1,
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
          }
        ],
      },
    };
  },
  methods: {
    /**修改开启和关闭配置 */
    async openAndClose(value, type) {
      let response = await common(
        baseURL.status+"/"+value.id,
        null,
        null,
        "PUT"
      );
      this.getList();
    },
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.get,
        null,
        null,
        "GET"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      let data = await common(baseURL.update, row, null, "POST");
      if (data == null) {
        loading();
        return;
      }
      this.getList();
      done();
    },
    /**保存 */
    async rowSave(row, done) {
      delete row["id"];
      let userInfo = this.$store.state.user.userInfo
      row.edit_admin_id = userInfo.id ? userInfo.id : null
      row.edit_admin_name = userInfo.username
      // row.last_operation_info = userInfo.username;
      row.edit_time = new Date();
      let data = await common(baseURL.save, row, null, "POST");
      this.getList();
      done();
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**删除 */
    rowDel(row) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        type: "warning",
      })
      .then(async () => {
        let response = await common(
          baseURL.delete,
          { id: row.id },
          null,
          "GET"
        );
      })
      .then(() => {
        this.getList();
      });
    },
    /**搜索 */
    searchChange(params, done) {
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  }
};
</script>

<style>
</style>